package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.PageBean;
import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.dto.YddCateDTO;
import com.itheima.advantagesup.entity.YddCate;
import com.itheima.advantagesup.service.YddCateService;
import com.itheima.advantagesup.vo.YddCateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: youdianda-1
 * @className: YddCateController
 * @description: 分类管理
 * @author: xch
 * @createTime: 2023-07-27 10:10
 **/
@Api(tags = "分类管理相关接口")
@RestController
@RequestMapping("/ydd_cate")
public class YddCateController {

    @Autowired
    private YddCateService yddCateService;

    /**
     * 换回全部分类列表
     *
     * @return
     */
    @ApiOperation("查询全部接口")
    @GetMapping("/all")
    public R<List<YddCate>> getAllCate() {
        List<YddCate> list = yddCateService.getAllCate();
        return R.success(list);
    }

    /**
     * 分类分页查询
     *
     * @param catename
     * @param page
     * @param limit
     * @return
     */
    @ApiOperation("分页查询接口")
    @GetMapping("/list")
    public R<PageBean> getListCate(String catename, Integer page, Integer limit) {
        PageBean pageBean = yddCateService.getListCate(catename, page, limit);
        return R.success(pageBean);
    }

    /**
     * Description 添加分类
     * @param yddCate
     * @return com.itheima.advantagesup.common.R<?>
     * Date 2023/7/29
     */
    @ApiOperation("添加分类接口")
    @PostMapping("/add")
    public R<?> addCate(@RequestBody YddCateDTO yddCate) {
        yddCateService.addCate(yddCate);
        return R.success();
    }

    /**
     * Description 更新分类
     * @param yddCate
     * @return com.itheima.advantagesup.common.R<?>
     * Date 2023/7/29
     */
    @ApiOperation("更新分类接口")
    @PostMapping("/update")
    public R<?> updateAllCate(@RequestBody YddCateDTO yddCate) {
        yddCateService.updateCate(yddCate);
        return R.success();
    }

    /**
     * Description 回显
     * @param id
     * @return com.itheima.advantagesup.common.R<?>
     * Date 2023/7/29
     */
    @ApiOperation("回显接口")
    @GetMapping("/rowInfo")
    public R<?> getOneCate(String id) {
        YddCateVO yddCateVO = yddCateService.getOneCate(id);
        return R.success(yddCateVO);
    }

    /**
     * Description 删除
     * @param id
     * @return com.itheima.advantagesup.common.R<?>
     * Date 2023/7/29
     */
    @ApiOperation("删除分类接口")
    @GetMapping("/del")
    public R<?> deleteCate(String id) {
        yddCateService.deleteCate(id);
        return R.success();
    }

}
